/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.foxline.converter;

import br.com.foxline.model.NatureWriting;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;

/**
 *
 * @author roniere
 */
@FacesConverter(value="naturewritingconverter")
public class NatureWritingConverter implements Converter{

    @Override
    public Object getAsObject(FacesContext context, UIComponent component, String value) {
        NatureWriting natureWriting = new NatureWriting();
        try{
            natureWriting.setId(Long.parseLong(value));
        }catch(Exception e){
            System.err.println("ERRO NA CONVERSÃO");
            e.printStackTrace();
            return null;
        }
        return natureWriting;
    }

    @Override
    public String getAsString(FacesContext context, UIComponent component, Object value) {
        NatureWriting natureWriting = (NatureWriting) value;
        return natureWriting.getId()+"";
    }
    
}
